import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Stack;


public class Path implements Cloneable{

	Stack<Node> stack;
	double costFunction;
	double heuristicDistance;
	double sourceDistance;
	int ID=0;
	
	public Path() {
		stack = new Stack<Node>();
		ID++;
	}
	
	public Path(Path other){
		this.costFunction = other.costFunction;
		this.stack = (Stack<Node>) copy(other.stack);
		this.heuristicDistance= other.heuristicDistance;
		this.sourceDistance=other.sourceDistance;
		this.ID=other.ID+1;
	}
	
	public Stack<Node> getStack() {
		return stack;
	}

	public void setStack(Stack<Node> stack) {
		this.stack = stack;
	}
	
	public double getCostFunction() {		
		return costFunction;
	}
	
	public void updateCostFucnction(){
		costFunction = sourceDistance + heuristicDistance;
	}

	public double getHeuristicDistance() {
		return heuristicDistance;
	}

	public void setHeuristicDistance(double heuristicDistance) {
		this.heuristicDistance = heuristicDistance;
	}

	public double getSourceDistance() {
		return sourceDistance;
	}

	public void setSourceDistance(double sourceDistance) {
		this.sourceDistance = this.sourceDistance + sourceDistance;
	}
	
	public Object copy(Object orig) {
	        Object obj = null;
	        try {
	            // Write the object out to a byte array
	            ByteArrayOutputStream bos = new ByteArrayOutputStream();
	            ObjectOutputStream out = new ObjectOutputStream(bos);
	            out.writeObject(orig);
	            out.flush();
	            out.close();

	            // Make an input stream from the byte array and read
	            // a copy of the object back in.
	            ObjectInputStream in = new ObjectInputStream(
	                new ByteArrayInputStream(bos.toByteArray()));
	            obj = in.readObject();
	        }
	        catch(IOException e) {
	            e.printStackTrace();
	        }
	        catch(ClassNotFoundException cnfe) {
	            cnfe.printStackTrace();
	        }
	        return obj;
	    }

}
